package id.co.rho.scoring.cid.client.widgets;

import com.extjs.gxt.ui.client.widget.form.NumberPropertyEditor;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;

/**
 * Created by IntelliJ IDEA.
 * User: bungrudi
 * Date: 8/6/11
 * Time: 10:44 PM
 */
public class BigDecimalSupportingPropertyEditor extends NumberPropertyEditor {

    public BigDecimalSupportingPropertyEditor() {
        super(BigDecimal.class);
    }

    @Override
    public Number convertStringValue(String value) {
        try {
            value = value.replaceAll(",","");
            BigDecimal val = new BigDecimal(value);
            return val.setScale(11, RoundingMode.HALF_UP);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String getStringValue(Number value) {
        return super.getStringValue(value);
    }
}
